#{extends 'main.html' /}

<h1>Edit the offer</h1>
<br>
<div id="styledForm">
#{form @Offers.save(offerId = offer.id), enctype:'multipart/form-data'}
    <fieldset>              
        <legend>Offer information</legend>  

        <div class="field">
            <label for="startDate">From</label>                  
            <input id="startDate" type="date" name="startDate" size="30" value="${offer.startDate.format('yyyy-MM-dd')}" class="#{errorClass 'startDate' /}" /> 
            <span class="error">#{error 'startDate' /}</span>
        </div>
        
        <div class="field">
            <label for="endDate">To</label>                  
            <input id="endDate" type="date" name="endDate" size="30" value="${offer.endDate.format('yyyy-MM-dd')}" class="#{errorClass 'endDate' /}" /> 
            <span class="error">#{error 'endDate' /}</span>
        </div>
        
        <div class="field">
            <label for="street">Street</label>                  
            <input id="street" type="text" name="street" size="30" value="${offer.street}" class="#{errorClass 'street' /}" /> 
            <span class="error">#{error 'street' /}</span>
        </div>       
        
        <div class="field">
            <label for="streetNumber">Street number</label>                  
            <input id="streetNumber" type="text" name="streetNumber" size="30" value="${offer.streetNumber}" class="#{errorClass 'streetNumber' /}" /> 
            <span class="error">#{error 'streetNumber' /}</span>
        </div>
        
        <div class="field">
            <label for="city">City</label>                  
            <input id="city" type="text" name="city" size="30" value="${offer.city}" class="#{errorClass 'city' /}" /> 
            <span class="error">#{error 'city' /}</span>
        </div> 
        
        <div class="field">
            <label for="zipcode">Zip Code</label>                  
            <input id="zipcode" type="text" name="zipcode" size="10" value="${offer.zipcode}" class="#{errorClass 'zipcode' /}" /> 
            <span class="error">#{error 'zipcode' /}</span>
        </div>   
        
        <div class="field">
            <label for="size">Room size</label>                  
            <input id="size" type="text" name="size" size="5" value="${offer.size}" class="#{errorClass 'size' /}" />  square meters
            <span class="error">#{error 'size' /}</span>
        </div>
        
        <div class="field">
            <label for="price">Room price</label>                  
            <input id="price" type="text" name="price" size="5" value="${offer.price}" class="#{errorClass 'price' /}" />Euro
            <span class="error">#{error 'price' /}</span>
        </div>                  
        
        <div class = "field"> 
			<label for = "event">Event</label>
			<select size="1" name="eventId">
            	#{list items:events, as:'event'}
                	<option value="${event.id}" #{if event.id == offer.event.id} selected #{/if}>${event.name}, 
                	#{if event.endDate == event.startDate}
                		on ${event.startDate.format('dd.MM.yyyy')}
                	#{/if}
                	#{else}	
                	from ${event.startDate.format('dd.MM.yyyy')} to ${event.endDate.format('dd.MM.yyyy')},
                	${event.city}
                	#{/else}
                	</option>
            	#{/list}
			</select>   
        </div>
        
        <div class="field">     
            <label for="description">Description</label>                    
            <textarea id="description" type="text" name="description" rows = "5" cols = "50" class="#{errorClass 'description' /}">${offer.description}</textarea>
            <span class="error">#{error 'description' /}</span>
       	</div>
        
        <div class="field">
         <label for="picture">Image</label>
         <input type="file" name="picture" value = "${offer.picture}" class="#{errorClass 'picture' /}" />
         <span class="error">#{error 'picture' /}</span>
        </div>  
        
        <div class="field">
         <label for="premium">Premium Offer?</label>
         <input type="checkbox" name="premium" value="true" ${offer.premium ? 'checked="true"' : ''}>
        </div>
    </fieldset>
                    
    <input type="submit" class="submit" value=" save " />
    
#{/form}
